#!/bin/bash
#
# neutron-ovs-cleanup  OpenStack Open vSwitch cleanup utility
#
# chkconfig:   - 97 02
# description: Purge Open vSwitch of the Neutron devices
### END INIT INFO

. /etc/rc.d/init.d/functions

proj=neutron
prog=$proj-ovs-cleanup
exec="/usr/bin/$prog"
pidfile="/var/run/$proj/$prog.pid"
configs=(
    "/usr/share/$proj/$proj-dist.conf" \
    "/etc/$proj/$proj.conf" \
    "/etc/$proj/plugins/openvswitch/ovs_neutron_plugin.ini" \
)
configs_str=${configs[@]/#/--config-file }

[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

lockfile=/var/lock/subsys/$prog

start() {
    [ -x $exec ] || exit 5
    for config in ${configs[@]}; do
        [ -f $config ] || exit 6
    done
    runuser -s /bin/bash neutron -c "$exec --log-file /var/log/$proj/ovs-cleanup.log $configs_str &>/dev/null"
    retval=$?
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}

case "$1" in
    start)
        $1
        ;;
    stop|restart|reload|force-reload|status|condrestart|try-restart)
        # Do nothing
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
        exit 2
esac
exit $?
